<template>
  <el-container class="admin-layout">
    <!-- Sidebar -->
    <el-aside :width="isCollapsed ? '64px' : '250px'" class="sidebar">
      <div class="logo-area">
        <n-icon v-if="isCollapsed" size="32" color="var(--color-primary)">
          <StorefrontOutline />
        </n-icon>
        <h2 v-else>Lucy Fashion Admin</h2>
      </div>
      
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapsed"
        :collapse-transition="false"
        router
      >
        <el-menu-item index="/dashboard">
          <el-icon><GridOutline /></el-icon>
          <template #title>Dashboard</template>
        </el-menu-item>
        
        <el-menu-item index="/categories">
          <el-icon><PricetagsOutline /></el-icon>
          <template #title>Categories</template>
        </el-menu-item>
        
        <el-menu-item index="/products">
          <el-icon><ShirtOutline /></el-icon>
          <template #title>Products</template>
        </el-menu-item>
        
        <el-menu-item index="/messages">
          <el-icon><ChatbubblesOutline /></el-icon>
          <template #title>Messages</template>
        </el-menu-item>
        
        <el-menu-item index="/store-settings">
          <el-icon><SettingsOutline /></el-icon>
          <template #title>Store Settings</template>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <!-- Main Content -->
    <el-container>
      <!-- Header -->
      <el-header class="header">
        <div class="header-left">
          <el-button 
            :icon="isCollapsed ? MenuOutline : CloseOutline" 
            circle 
            @click="isCollapsed = !isCollapsed"
          />
          <span class="page-title">{{ currentPageTitle }}</span>
        </div>
        
        <div class="header-right">
          <el-button @click="goToWebsite" type="primary" plain>
            <n-icon size="18" style="margin-right: 0.5rem;"><GlobeOutline /></n-icon>
            Visit Website
          </el-button>
        </div>
      </el-header>

      <!-- Content -->
      <el-main class="main-content">
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { NIcon } from 'naive-ui'
import {
  StorefrontOutline,
  GridOutline,
  PricetagsOutline,
  ShirtOutline,
  ChatbubblesOutline,
  SettingsOutline,
  MenuOutline,
  CloseOutline,
  GlobeOutline
} from '@vicons/ionicons5'

const route = useRoute()
const isCollapsed = ref(false)

const activeMenu = computed(() => route.path)

const currentPageTitle = computed(() => route.meta.title || 'Dashboard')

const goToWebsite = () => {
  window.open('/', '_blank')
}
</script>

<style lang="scss" scoped>
.admin-layout {
  height: 100vh;
}

.sidebar {
  background-color: var(--color-white);
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
  transition: width 0.3s;
}

.logo-area {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  border-bottom: 1px solid #e8e8e8;
  
  h2 {
    font-size: 1.25rem;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
  }
}

.el-menu {
  border-right: none;
  
  :deep(.el-icon) {
    font-size: 20px;
  }
}

.header {
  background-color: var(--color-white);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.main-content {
  background-color: #f5f5f5;
  padding: 2rem;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    z-index: 1000;
    height: 100vh;
  }
  
  .main-content {
    padding: 1rem;
  }
}
</style>

